package com.derive.education_service.web.registration.controller;
import com.derive.education_service.common.global.Paper;
import com.derive.education_service.common.global.ResponseMessage;
import com.derive.education_service.entity.Registration;
import com.derive.education_service.web.registration.bean.dto.InfoIntentionAddDto;
import com.derive.education_service.web.registration.bean.dto.QueryParam;
import com.derive.education_service.web.registration.service.RegistrationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 信息登记操作接口
 */
@RestController
@RequestMapping("registration")
@Slf4j
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    /**
     * 信息登记
     * @param intentionAddDto
     * @return
     */
    @PostMapping("addInfoIntention")
    public ResponseMessage addInfoIntention(@RequestBody InfoIntentionAddDto intentionAddDto) {
        return registrationService.addInfoIntention(intentionAddDto);
    }

    /**
     * 标记登记信息 -- 设置为已读 tag=0，默认为1
     * @param resId
     * @return
     */
    @PostMapping("tagInfoIntention")
    public ResponseMessage tagInfoIntention(int resId) {
        return registrationService.tagInfoIntention(resId);
    }

    /**
     * 删除登记信息 -- 物理删除
     * @param resId
     * @return
     */
    @PostMapping("delInfoIntention")
    public ResponseMessage delInfoIntention(int resId) {
        return registrationService.delInfoIntention(resId) ? ResponseMessage.createBySuccessMessage("成功")
                : ResponseMessage.createByErrorMessage("异常");
    }

    /**
     * 查询登记详情
     * @param resId
     * @return
     */
    @GetMapping("getRegistrationById")
    public ResponseMessage getRegistrationById(int resId) {
        Registration registration = registrationService.getRegistrationById(resId);
        return registration == null ? ResponseMessage.createByErrorMessage("不存在该信息")
                : ResponseMessage.createBySuccess(registration);
    }

    /**
     * 查询登记列表信息 -- 分页查询 -- 条件查询 -- 时间倒序
     * @param queryParam
     */
    @PostMapping("getRegistrationList")
    public ResponseMessage getRegistrationList(@RequestBody QueryParam queryParam) {
        Paper<Registration> registrationPaper = registrationService.getRegistrationList(queryParam);
        return ResponseMessage.createBySuccess(registrationPaper);
    }
}
